import React, { useEffect } from "react"
import PubSub from "pubsub-js";
import "./Header.css"
export default function Header() {
  function handle(e) {
    if (e.keyCode !== 13) return
    if(!e.target.value.trim()) return e.target.value = ""
    PubSub.publish("add",e.target.value.trim())
    e.target.value = ""
  }
  

  return (
    <div className="todo-header">
      <input
        type="text"
        placeholder="请输入你的任务名称，按回车键确认"
        onKeyDown={handle}
      />
    </div>
  )
}
